#include "CardDataClass.h"

CardData::CardData(const CardData& card)
{
	name = card.name;
	points = card.points;
	color = card.color;
	features = card.features;
	power = card.power;
	ID = card.ID;
	value = card.value;
	targetInfluence = card.targetInfluence;
	targetArea = card.targetArea;
	targetAttributes = card.targetAttributes;
	targetColor = card.targetColor;
	targetID = card.targetID;
	cardImage = card.cardImage;
}
/*	SET(INPUT) FUNCTIONS  */
	void CardData::setName(string aName){name = aName;}
	void CardData::setPoints(int aPointValue){points = aPointValue;}
	void CardData::setColor(int aColor){color = aColor;}
	void CardData::setFeatures(int aFeature){features = aFeature;}
	void CardData::setPower(string aPower){power = aPower;}
	void CardData::setID(int anID){ID = anID;}		//<--Probably shouldn't be used...for obvious reasons
		//Target information
	void CardData::setValue(int aValue){value = aValue;}
	void CardData::setInfluence(int anInfluence){targetInfluence = anInfluence;}
	void CardData::setTargetArea(int aTarget){targetArea = aTarget;}
	void CardData::setTargetAttributes(int anAttribute){targetAttributes = anAttribute;}
	void CardData::setTargetColor(int aColor){targetColor = aColor;}
	void CardData::setTargetID(int anID){targetID = anID;}

/*  GET(OUTPUT) FUNCTIONS */
	string CardData::getName() {return name;}
	int CardData::getPoints() {return points;}
	int CardData::getColor() {return color;}
	int CardData::getFeatures() {return features;}
	string CardData::getPower() {return power;}
	int CardData::getID() {return ID;}
		//Target infomation
	int CardData::getValue(){return value;}
	int CardData::getInfluence(){return targetInfluence;}
	int CardData::getTargetArea(){return targetArea;}
	int CardData::getTargetAttributes(){return targetAttributes;}
	int CardData::getTargetColor(){return targetColor;}
	int CardData::getTargetID(){return targetID;}

/*	RESOLVE POWER FUNCTIONS */
	void CardData::ResolvePower(CardData homeField[], CardData oppositeField[])
	{
		bool targetFound = false;		//The king of these bools.  Will determine if the card the logic is examining was a hit (Only after tested against everything else.
		CardData theOtherCard;				//A holder to look at other cards and compare them to this card
		stack<CardData> matches;		//A holder to keep track of matches (for cards that can target multiple other cards.)

		if (this->getTargetArea() & SELF_TARGET)	//Card targets itself. (I.E.:  The power always triggers)
		{
			targetFound = true;
		}
		if (this->getTargetArea() & OPPOSITE_TARGET)//Card targets the card opposite itself on the playfield
		{
			/*  Some logic to locate the card opposite this cards position, and to 
			determine if it is a match.  */
			int location = 0;		//The location of the found card.
			for (int i = 0; i < 12; ++i)	//Loop through the cards in homeField until this cards position is found.
			{
				theOtherCard = homeField[i];
				if (this->getID() == theOtherCard.getID())
				{
					location = i;
					i = 12;	//End the loop early.
				}
			}
			/*  Now that the cards position is found, we can do some logic to compare it's data to the data of the card in oppositeField[location] */
			if (this->AttributesMatch(oppositeField[location]) || this->ColorsMatch(oppositeField[location]) || this->IDMatch(oppositeField[location]))
			{
				/* The card matched a target attribute.  We can finially record that we found the target.  */
				matches.push(oppositeField[location]);
				targetFound = true;
			}
		}
		if (this->getTargetArea() & ADJACENT_TARGET)
		{
			/*  Some logic to parse through all the cards adjacent to this card,
			and to check which ones of them match the target.  */
		}
		if (this->getTargetArea() & INPLAY_TARGET)
		{
			/*  Some logic to parse through all the cards in play and to see if they match the target.  */
			for (int i = 0; i < 12; ++i)
			{
				if (this->AttributesMatch(oppositeField[i]) || this->ColorsMatch(oppositeField[i]) || this->IDMatch(oppositeField[i]))
				{
					matches.push(oppositeField[i]);
					targetFound = true;
				}
				if (this->AttributesMatch(homeField[i]) || this->ColorsMatch(homeField[i]) || this->IDMatch(homeField[i]))
				{
					matches.push(homeField[i]);
					targetFound = true;
				}
			}
		}
		/*  Here is where I will do stuff with the matches I've found  */
		if (targetFound == true)
		{
			while(matches.size() > 0)  //While we still have matches in the stack.
			{
				matches.top().setPoints(matches.top().getPoints() + this->getValue()); //Change the points of the match by this cards value
				matches.pop();	//Remove it from the stack.
			}
		}
	}

	bool CardData::AttributesMatch(CardData theOtherCard)
	{
		if (this->targetAttributes & theOtherCard.getFeatures())	//If this cards targetAttributes flag finds a match in the otherCards features flag
			return true;
		else
			return false;
	}

	bool CardData::ColorsMatch(CardData theOtherCard)
	{
		if (this->targetColor & theOtherCard.getColor())	//If this cards targetColor flag finds a match in the otherCards color flag
			return true;
		else
			return false;
	}

	bool CardData::IDMatch(CardData theOtherCard)
	{
		if (this->targetID == theOtherCard.getID())	//If this cards targetID matches the other cards actual ID.
			return true;
		else
			return false;
	}

/*  Drawing Function(s)  */
	void CardData::drawCardSmall()
	{

	}

	void CardData::drawCardLarge()
	{

	}